import 'package:flutter_bilibili/dao/user_dao.dart';
import 'package:flutter_bilibili/http/core/fw_error.dart';
import 'package:flutter_bilibili/util/string_util.dart';
import 'package:get/get.dart';

import 'login_state.dart';

class LoginLogic extends GetxController {
  final LoginState state = LoginState();

  RxBool protect = false.obs;
  RxBool loginEnable = false.obs;
  String? userName;
  String? password;

  void checkInput() {
    bool enable;
    if (isNotEmpty(userName) && isNotEmpty(password)) {
      enable = true;
    } else {
      enable = false;
    }
    loginEnable.value = enable;
  }

  void send() async {
    print("object");
    try {
      var result = await UserDao.login(userName!, password!);
      if (result['code'] == 0) {
        print('登录成功');
      } else {
        print(result['msg']);
      }
    } on NeedAuth catch (e) {
      print(e);
    } on FwNetError catch (e) {
      print(e);
    }
  }
}
